package com.txd.mofa.fabu.aty;
import android.content.Intent;
import android.os.Environment;
import android.util.Log;
import android.widget.FrameLayout;
import android.widget.Toast;

import com.kongzue.baseframework.interfaces.Layout;
import com.kongzue.baseframework.util.JumpParameter;
import com.txd.mofa.R;
import com.txd.mofa.base.BaseAty;
import com.txd.mofa.net.NetUtils;
import com.txd.mofa.utils.GlideEngine;
import com.txd.mofa.xiangce.EasyPhotos;
import com.txd.mofa.xiangce.models.album.entity.Photo;

import java.util.ArrayList;
import java.util.List;

@Layout(R.layout.aty_xiangce)
public class XiangceAty extends BaseAty {


    @Override
    public void initViews() {
        super.initViews();

        EasyPhotos.createAlbum(this, false, GlideEngine.getInstance())
                .start(101);
    }

    @Override
    protected void onNetworkConnected(NetUtils.NetType type) {

    }

    @Override
    protected void onNetworkDisConnected() {

    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
//        if (albumItemsAdView != null) {
//            if (albumItemsAdView.getParent() != null) {
//                ((FrameLayout) (albumItemsAdView.getParent())).removeAllViews();
//            }
//        }
//        if (photosAdView != null) {
//            if (photosAdView.getParent() != null) {
//                ((FrameLayout) (photosAdView.getParent())).removeAllViews();
//            }
//        }
        if (RESULT_OK == resultCode) {
            //相机或相册回调
            if (requestCode == 101) {
                //返回对象集合：如果你需要了解图片的宽、高、大小、用户是否选中原图选项等信息，可以用这个
                ArrayList<Photo> resultPhotos = data.getParcelableArrayListExtra(EasyPhotos.RESULT_PHOTOS);

                //返回图片地址集合时如果你需要知道用户选择图片时是否选择了原图选项，用如下方法获取
                boolean selectedOriginal = data.getBooleanExtra(EasyPhotos.RESULT_SELECTED_ORIGINAL, false);

                Log.e("resultPhotos",resultPhotos.toString());

                finish();

//                selectedPhotoList.clear();
//                selectedPhotoList.addAll(resultPhotos);
//                adapter.notifyDataSetChanged();
//                rvImage.smoothScrollToPosition(0);

                return;
            }

//            //为拼图选择照片的回调
//            if (requestCode == 102) {
//
//                ArrayList<Photo> resultPhotos =
//                        data.getParcelableArrayListExtra(EasyPhotos.RESULT_PHOTOS);
//                if (resultPhotos.size() == 1) {
//                    resultPhotos.add(resultPhotos.get(0));
//                }
//                selectedPhotoList.clear();
//                selectedPhotoList.addAll(resultPhotos);
//
//                EasyPhotos.startPuzzleWithPhotos(this, selectedPhotoList, Environment.getExternalStorageDirectory().getAbsolutePath(), "AlbumBuilder", 103, false, GlideEngine.getInstance());
//                return;
//            }
//
//            //拼图回调
//            if (requestCode == 103) {
//                Photo puzzlePhoto = data.getParcelableExtra(EasyPhotos.RESULT_PHOTOS);
//                selectedPhotoList.clear();
//                selectedPhotoList.add(puzzlePhoto);
//                adapter.notifyDataSetChanged();
//                rvImage.smoothScrollToPosition(0);
//            }


        } else if (RESULT_CANCELED == resultCode) {
//            Toast.makeText(this, "cancel", Toast.LENGTH_SHORT).show();
            finish();
        }
    }

    @Override
    public void initDatas(JumpParameter paramer) {

    }

    @Override
    public void setEvents() {

    }
}
